package edu.uci.ics.ai.maze.testing;

import edu.uci.ics.ai.maze.models.Maze;
import edu.uci.ics.ai.maze.models.Vertex;
import edu.uci.ics.ai.maze.models.Edge;
import edu.uci.ics.ai.maze.models.Polygon;
import java.util.Arrays;
import java.util.Iterator;

import static org.junit.Assert.*;

/**
 *
 * @author dpurpura
 */
public final class Assert {

  public static void assertMaze(Maze expected, Maze actual) {
    assertVertex(expected.getStart(), actual.getStart());
    assertVertex(expected.getGoal(), actual.getGoal());
    Iterator<Polygon> expectedPolygonIt = expected.getPolygons().iterator();
    Iterator<Polygon> actualPolygonIt = actual.getPolygons().iterator();
    while (expectedPolygonIt.hasNext()) {
      assertPolygon(expectedPolygonIt.next(), actualPolygonIt.next());
    }
  }


  public static void assertPolygon(Polygon expected, Polygon actual) {
    assertEquals(expected.getVertices().size(), actual.getVertices().size());
    assertEquals(expected.getEdgesCount(), actual.getEdgesCount());

    Iterator<Edge> expectedEdgesIt = Arrays.asList(expected.getEdges()).iterator();
    Iterator<Edge> actualEdgesIt = Arrays.asList(actual.getEdges()).iterator();
    for (int i = 0; i < expected.getEdgesCount(); i++) {
      assertEdge(expectedEdgesIt.next(), actualEdgesIt.next());
    }

    for (Vertex v : actual.getVertices()) {
      assertEquals(actual, v.getPolygon());
    }
    assertEquals(expected.getColor(), actual.getColor());
  }

  public static void assertEdge(Edge expected, Edge actual) {
    assertEquals(expected.getStart(), actual.getStart());
    assertEquals(expected.getEnd(), actual.getEnd());
  }

  public static void assertVertex(Vertex expected, Vertex actual) {
    assertEquals(expected.getX(), actual.getX());
    assertEquals(expected.getY(), actual.getY());
    assertEquals(expected.getPolygon(), actual.getPolygon());
  }
}
